import csv
import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from loguru import logger


def get_step_name():
    options = webdriver.ChromeOptions()
    browser = webdriver.Chrome(executable_path=ChromeDriverManager(path='../../').install(), options=options)
    browser.implicitly_wait(5)
    browser.get("https://xuat.wxp.woa.com/assistant/caseInputManagement")
    browser.find_element(By.ID, "btn_smartlogin").click()  # oa登录
    time.sleep(1)
    browser.maximize_window()
    browser.get("https://xuc.wxp.woa.com/#/?useCaseId=1&branchType=1&branchId=1&useCaseInstanceVer=144")
    time.sleep(10)
    browser.find_element_by_xpath("//button[contains(text(),'关闭')]").click()
    browser.find_element_by_xpath("//i[contains(text(),'展开所有')]").click()

    num = 1
    label_list = [0]
    while label_list:

        title_value = ''
        label_list = browser.find_elements_by_xpath("//div[@class='virtual-tree-text']")
        for label in label_list:
            title_value = label.text.replace('\n', '')
            logger.info(f'{num}, {title_value}')
            num += 1

            print('title_value:', title_value)
            if '22.【系统】反馈收款结果' == title_value:
                break
        if '22.【系统】反馈收款结果' == title_value:
            break

        label_list_end = title_value.split(".")[0]
        element = browser.find_element_by_xpath("//span[@class='virtual-tree-text__label' and contains(@title,'%s')]" % label_list_end)
        browser.execute_script("arguments[0].scrollIntoView();", element)
        time.sleep(2)

    browser.quit()



if __name__ == '__main__':
    get_step_name()
